package models

import (
	"errors"
	"github.com/sirupsen/logrus"
)

// SpecialIndustryActivity 特殊行业活动表
type SpecialIndustryActivity struct {
	Model
	Name         string  `gorm:"column:name;type:varchar(255);not null" json:"name"`
	Type         int     `json:"type" gorm:"comment:'费率类型 0=D0 1=D1'"`
	Wechat       float64 `json:"wechat" gorm:"type:decimal(10,6);comment:'微信费率'"`
	Alipay       float64 `json:"alipay" gorm:"type:decimal(10,6);comment:'支付宝费率'"`
	YunPayMin    float64 `json:"yun_pay_min" gorm:"type:decimal(10,6);comment:'云闪付费率<=1000元'"`
	YunPayMax    float64 `json:"yun_pay_max" gorm:"type:decimal(10,6);comment:'云闪付费率>1000元'"`
	DebitCard    float64 `json:"debit_card" gorm:"type:decimal(10,6);comment:'刷卡储蓄卡费率'"`
	DebitCardMax float64 `json:"debit_card_max" gorm:"type:decimal(10,6);comment:'刷卡储蓄卡封顶手续费'"`
	CreditCard   float64 `json:"credit_card" gorm:"type:decimal(10,6);comment:'刷卡信用卡费率'"`
}

// SpecialIndustryActivityInfoAdd 添加特殊行业活动
func SpecialIndustryActivityInfoAdd(sia SpecialIndustryActivity) error {
	err := db.Create(&sia).Error
	if err != nil {
		logrus.WithError(err).Errorf("添加特殊行业活动失败 err:%v,dev:%v", err, sia)
		return errors.New("添加特殊行业活动失败")
	}
	return nil
}

// SpecialIndustryActivityList 获取特殊行业列表
func SpecialIndustryActivityList(pageSize, pageNum int) (map[string]interface{}, error) {
	var (
		list  = make([]map[string]string, 0)
		count int64
	)

	err := db.Select("id,name").Model(SpecialIndustryActivity{}).Limit(pageSize).Offset((pageNum - 1) * pageSize).Scan(&list).Order("created_at DESC").Error
	db.Model(&SpecialIndustryActivity{}).Count(&count)
	if err != nil {
		logrus.WithError(err).Errorf("获取特殊行业列表失败 err:%v", err)
		return nil, errors.New("添加特殊行业活动失败")
	}
	return map[string]interface{}{
		"list":  list,
		"count": count,
	}, nil
}
